package com.javasm.commons.basic;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


public class BaseServiceImpl<D extends BaseDao<T>,T> implements BaseService<T>{
    @Autowired
    protected D baseDao;

    @Override
    public T queryById(Object id) {
        return this.baseDao.queryById((Integer) id);
    }

    @Override
    public List<T> queryByIds(List ids) {
        return (List) this.baseDao.queryByIds( ids);
    }

    @Override
    public List<T> queryList(T obj) {
        return this.baseDao.queryAll(obj);
    }

    @Override
    public Boolean insert(T obj) {
        int rows = this.baseDao.insert(obj);
        return rows==1;
    }

    @Override
    public Boolean update(T obj) {
        int rows = this.baseDao.update(obj);
        return rows==1;
    }

    @Override
    public Boolean deleteById(Object id) {
        return this.baseDao.deleteById((Integer) id) > 0;
    }

    @Override
    public Boolean deleteByIds(List ids) {
        int i = this.baseDao.deleteByIds(ids);
        return i==ids.size();
    }
}
